package cn.zjk.springframework.context.support;

import cn.zjk.springframework.beans.BeansException;
import cn.zjk.springframework.beans.factory.ConfigurableListableBeanFactory;
import cn.zjk.springframework.beans.factory.support.DefaultListableBeanFactory;

/**
 * @author zjk
 * @CreateTime 2023/3/27 23:22
 */
public abstract class AbstractRefreshableApplicationContext extends AbstractApplicationContext{

    private DefaultListableBeanFactory beanFactory;
    @Override
    protected void refreshBeanFactory() throws BeansException {
        DefaultListableBeanFactory beanFactory = createBeanFactory();
        loadBeanDefinitions(beanFactory);
        this.beanFactory = beanFactory;
    }

    private DefaultListableBeanFactory createBeanFactory(){
        return new DefaultListableBeanFactory();
    }

    /**
     * 资源配置的加载操作
     * @param beanFactory
     */
    protected abstract void loadBeanDefinitions(DefaultListableBeanFactory beanFactory);

    @Override
    protected ConfigurableListableBeanFactory getBeanFactory() {
        return beanFactory;
    }
}
